import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/cart/cart_router.dart';
import 'package:flutter_shop/pages/common/common_router.dart';
import 'package:flutter_shop/pages/home/home_router.dart';
import 'package:flutter_shop/pages/member/member_router.dart';
import 'package:flutter_shop/routers/404.dart';
import 'package:flutter_shop/routers/router_init.dart';

///Title:路由统一注册 <br/>
///Description: <br/>
///author:xiemiao <br/>
///date: 2020-02-21 <br/>
///version 1.0 <br/>
class Routers {
  static Router router;

  ///存各模块Router管理类
  static List<IRouterProvider> _listRouter = [];

  ///注册路由
  static void configureRoutes(Router router) {
    Routers.router = router;

    // 指定路由跳转错误返回页
    router.notFoundHandler = Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      debugPrint('页面404');
      return PageNotFound();
    });

    _listRouter.clear();

    //各模块路由在此添加
    _listRouter.add(CommonRouter()); //常规路由
    _listRouter.add(HomeRouter()); //首页模块路由
    _listRouter.add(CartRouter()); //购物车模块路由
    _listRouter.add(MemberRouter()); //会员中心路由

    // 统一定义路由
    _listRouter.forEach((routerProvider) {
      routerProvider.initRouter(router);
    });
  }
}
